<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改扩展资料</title>
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/style.css">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
    <style type="text/css">
        .col-sm-10 {width: 320px;display: inline-block;}
        .col-sm-2 {text-align: right;width: 125px;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal" onsubmit="return false">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属学校</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="school_id">
                                    <option value="">…请选择学校…</option>
                                    {foreach($school as $s)}
                                    <option value="{$s.id}" {if($s.id==($user_attr.school_id??''))}selected="selected"{/if}>{$s.school_name}</option>
                                    {/foreach}
                                </select>
                                <input type="hidden" name="school_name" value="{$user_attr.school_name??''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属年级</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="grade_id">
                                    <option value="">…请选择年级…</option>
                                    {foreach($grade as $g)}
                                    <option value="{$g.id}" {if($g.id==($user_attr.grade_id??''))}selected="1"{/if}>{$g.grade_name}</option>
                                    {/foreach}
                                </select>
                                <input type="hidden" name="grade_name" value="{$user_attr.grade_name??''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属班级</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="class_id">
                                    <option value="">…请选择班级…</option>
                                    {foreach($banji as $b)}
                                    <option value="{$b.id}" {if($b.id==($user_attr.class_id??''))}selected="1"{/if}>{$b.class_name}</option>
                                    {/foreach}
                                </select>
                                <input type="hidden" name="class_name" value="{$user_attr.class_name??''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">民族</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="nation">
                                    <option value="">…请选择民族…</option>
                                    {foreach($nations as $n)}
                                    <option value="{$n}" {if($n==($user_attr.nation??''))}selected="1"{/if}>{$n}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {foreach $fields as $field}
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{$field.field_txt}</label>
                            <div class="col-sm-10">
                                {if($field.field_type==='string')}
                                <input type="text" class="form-control" name="{$field.field_name}" value="{$user_attr[$field.field_name]??''}" placeholder="{$field.field_txt}" autocomplete="off">
                                {elseif($field.field_type==='int')}
                                <input type="number" class="form-control" name="{$field.field_name}" value="{$user_attr[$field.field_name]??''}" placeholder="{$field.field_txt}" autocomplete="off">
                                {elseif($field.field_type==='date')}
                                <input type="text" class="laydate-icon form-control roy-date" id="t{$field.field_name}" name="{$field.field_name}" value="{$user_attr[$field.field_name]??''}" placeholder="{$field.field_txt}" autocomplete="off">
                                {elseif($field.field_type==='datetime')}
                                <input type="text" class="laydate-icon form-control roy-datetime" id="d{$field.field_name}" name="{$field.field_name}" value="{$user_attr[$field.field_name]??''}" placeholder="{$field.field_txt}" autocomplete="off">
                                {elseif($field.field_type==='select')}
                                <select class="form-control" name="{$field.field_name}">
                                    <option value="">…请选择…</option>
                                    {foreach $field.field_value as $k=>$v}
                                    <option value="{$k}" {if($k==($user_attr[$field.field_name]??''))}selected="selected"{/if}>{$v}</option>
                                    {/foreach}
                                </select>
                                {elseif($filed.field_type==='radio')}
                                <div class="radio i-checks">
                                    {foreach $field.field_value as $k=>$v}
                                    <label class>
                                        <div class="iradio_square-green">
                                            <input type="radio" value="{$k}" name="gender" style="position: absolute; opacity: 0;">
                                            <ins class="iCheck-helper"></ins>
                                        </div>
                                        {$v}</label>
                                    {/foreach}
                                </div>
                                {/if}
                            </div>
                        </div>
                        {/foreach}
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/hplus/js/jquery.min.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/layui/layui.js?v={php}echo time(){/php}"></script>
<script type="text/javascript">
    $(function () {
        layui.use('laydate', function () {
            let $laydate = layui.laydate
            $('.roy-date').each(function ($i, $obj) {
                $laydate.render({
                    elem: '#' + $obj.id
                })
            })
            $('.roy-datetime').each(function ($i, $obj) {
                $laydate.render({
                    elem: '#' + $obj.id,
                    type: 'datetime'
                })
            })
        })
        $('[name="school_id"]').change(function () {
            let $school_id = $(this).val()
            let $school_name = $(this).find('option:checked').text()
            $('[name="school_name"]').val($school_id!==''?$school_name:'')
            $('[name="grade_name"]').val('')
            $('[name="class_name"]').val('')
            $('[name="grade_id"]').html('<option value="">…请选择年级…</option>')
            $('[name="class_id"]').html('<option value="">…请选择班级…</option>')
            if ($school_id !== '') {
                $.ajax({
                    type: 'post', dataType: 'json', cache: false,
                    url: '/user/get_grade',
                    data: {'school_id': $school_id},
                    success: function ($data) {
                        if ($data.code === 200 && $data.data != null) {
                            let $str = '';
                            $($data.data).each(function ($i, $v) {
                                $str += '<option value="' + $v.id + '">' + $v.grade_name + '</option>'
                            })
                            $('[name="grade_id"]').append($str)
                        } else {
                            layer.msg($data.message)
                            return false
                        }
                    }
                })
            }
        });
        $('[name="grade_id"]').change(function () {
            let $grade_name = $(this).find('option:checked').text()
            $('[name="grade_name"]').val($grade_name)
            $('[name="class_name"]').val('')
            let $grade_id = $(this).val()
            $('[name="class_id"]').html('<option value="">…请选择班级…</option>')
            if ($grade_id !== '') {
                $.ajax({
                    type: 'post', dataType: 'json', cache: false,
                    url: '/user/get_banji',
                    data: {'grade_id': $grade_id},
                    success: function ($data) {
                        if ($data.code === 200 && $data.data != null) {
                            let $str = '';
                            $($data.data).each(function ($i, $v) {
                                $str += '<option value="' + $v.id + '">' + $v.class_name + '</option>'
                            })
                            $('[name="class_id"]').append($str)
                        } else {
                            layer.msg($data.message)
                            return false
                        }
                    }
                })
            }
        })
        $('[name="class_id"]').change(function () {
            let $class_name = $(this).find('option:checked').text()
            $('[name="class_name"]').val($class_name)
        })
    })
</script>
</html>
